package com.karaoke.android.kege.fragment


import android.os.Bundle
import android.support.v4.app.Fragment
import com.apkfuns.logutils.LogUtils
import com.karaoke.android.data.domain.QSong
import com.karaoke.android.kege.BR
import com.karaoke.android.kege.R
import com.karaoke.android.kege.databinding.FragmentSongPageBinding
import com.karaoke.android.kege.vm.SongPageViewModel
import com.karaoke.android.library.mvvm.BindingConfig
import com.karaoke.android.library.mvvm.MvvmFragment


/**
 * A simple [Fragment] subclass.
 */
class SongPageFragment : MvvmFragment<SongPageViewModel>()
{

    override val viewModel: SongPageViewModel by lazy { SongPageViewModel() }
    override val config: BindingConfig by lazy { BindingConfig(R.layout.fragment_song_page, BR.viewModel) }
    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
        val langId = arguments.getInt("LanguageId", 0)
        val typeId = arguments.getInt("TypeId", 0)
        val qType = arguments.getString("QueryType")
        val wordCount = arguments.getInt("WordCount", 0)
        viewModel.qSong.criteria = langId
        if (wordCount > 0) viewModel.qSong.criteria = wordCount
        viewModel.qSong.typeId = typeId
        viewModel.qSong.queryType = QSong.QueryType.valueOf(qType)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?)
    {
        super.onActivityCreated(savedInstanceState)
        LogUtils.e("onActivityCreated")
    }

    override fun onDestroyView()
    {
        super.onDestroyView()
        viewModel.position.set((dataBinding as FragmentSongPageBinding).gridView.firstVisiblePosition)
    }

}
